package com.starter;

import git.oschina.dushougudu.annotation.SpringAutoService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(PersonConfigProperties.class)
@ConditionalOnClass(Person.class)
@SpringAutoService(EnableAutoConfiguration.class)
public class MyStarterAutoConfiguration {


    @Bean
    @ConditionalOnProperty(prefix = "mystarter.config", name = "enable", havingValue = "true")
    public Person defaultStudent(PersonConfigProperties personConfigProperties) {
        Person person = new Person();
        person.setAge(personConfigProperties.getAge());
        person.setName(personConfigProperties.getName());
        person.setGender(personConfigProperties.getGender());
        return person;
    }
}
